package com.example.mobile2021606129ly0330;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity_fen extends AppCompatActivity {

    private EditText edFenX;
    private Button butFenRes;
    private TextView textFenRes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_fen);
        initView();
    }



            private void initView () {
                edFenX = (EditText) findViewById(R.id.ed_fen_x);
                butFenRes = (Button) findViewById(R.id.but_fen_res);
                textFenRes = (TextView) findViewById(R.id.text_fen_res);
            }

    double y;
    public void resultonClick(View view) {
        String a = edFenX.getText().toString();
        if (a.length() == 0) {
            Toast.makeText(MainActivity_fen.this, "请输入x的值", Toast.LENGTH_SHORT).show();
        } else {
            double x = Double.parseDouble(a);
            if (x < 1) {
                y = x;
                textFenRes.setText(String.valueOf(y));
            } else if (1 <= x && x < 10) {
                y = 2 * x - 1;
                String str = String.format("%.2f", y);
                textFenRes.setText(String.valueOf(str));
            } else if (x >= 10) {
                y = 3 * x - 11;
                String str = String.format("%.2f", y);
                textFenRes.setText(String.valueOf(str));
            }
        }
        }
    }